package club.calong.sanniu.util;

import club.calong.sanniu.http.request.InfoRequest;
import club.calong.sanniu.http.request.PlateRequest;
import club.calong.sanniu.http.request.SectionRequest;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CheckUtils {

    /**
     * 校验某个字符是否是a-z、A-Z、_、0-9
     *
     * @param str 被校验的字符串
     * @return true 代表符合条件
     */
    public static boolean isWord(String str) {

        if (str == null)
            return false;

        String regEx = "[\\w]";
        char[] chars = str.toCharArray();
        for (char c : chars) {
            Pattern p = Pattern.compile(regEx);
            if (!p.matcher("" + c).matches())
                return false;
        }
        return true;
    }

    public static boolean checkPlate(PlateRequest plate){

        return plate.getSection() !=null && plate.getContent() != null;
    }



    public static boolean isSpecialChar(String str) {

        String regEx = "[ _`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？]|\n|\r|\t";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.find();
    }

    public static boolean checkSection(SectionRequest section){

        return section.getSection() != null && section.getType() != null;
    }

    public static boolean checkInfo(InfoRequest info){
        return info.getName() != null && info.getCaseNumber() != null && info.getCompany() != null &&
                info.getDesc() != null && info.getEmail() != null && info.getPhone() != null &&
                info.getPrincipal() != null;
    }
}
